home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 14 / CU Amiga Magazine's Super CD-ROM 14 (1997)(EMAP Images)(GB)(Track 1 of 3)[!][issue 1997-09].iso / CUCD / Programming / XPK / Source / xpkmaster / progress.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-06-06  |  1.8 KB  |  75 lines

  1. #ifndef XPKMASTER_PROGRESS_C
  2. #define XPKMASTER_PROGRESS_C
  3.  
  4. /* Routinesheader
  5.  
  6.     Name:        progress.c
  7.     Main:        xpkmaster
  8.     Versionstring:    $VER: progress.c 1.1 (24.03.97)
  9.     Author:        SDI
  10.     Distribution:    PD
  11.     Description:    Progress report handler
  12.  
  13.  1.0   06.10.96 : first real version
  14.  1.1   24.03.97 : added auto hook, changed speed calculation
  15.  1.2   25.04.97 : changed time calculation
  16. */
  17.  
  18. #include <exec/types.h>
  19. #include <pragma/intuition_lib.h>
  20. #include "xpkmaster.h"
  21.  
  22. LONG callprogress(struct XpkBuffer *xbuf)
  23. {
  24.   struct XpkProgress *prog = &xbuf->xb_Prog;
  25.   struct Hook *hk = xbuf->xb_ChunkHook;
  26.   struct XpkPrefsSemaphore *sem = 0;
  27.  
  28.   if(!hk && (xbuf->xb_Flags & XMF_AUTOPRHOOK) && (sem = GetPrefsSem()))
  29.     hk = sem->xps_ProgressHook;
  30.  
  31.   if(hk)
  32.   {
  33.     if(prog->xp_UCur && prog->xp_ULen)
  34.     {
  35.       ULONG secs;
  36.       LONG mics;
  37.  
  38.       CurrentTime (&secs, (ULONG *) &mics);
  39.       secs -= xbuf->xb_Secs;
  40.       mics -= xbuf->xb_Mics;
  41.  
  42.       /* 7813 = 100000 / 128, 0x20000000 = 0x100000000/128 (ULONG size),
  43.          +1 prevents division by zero */
  44.       if(prog->xp_UCur < 0x20000000)
  45.         prog->xp_Speed = (prog->xp_UCur<<7) / ((secs<<7) + mics/7813 + 1);
  46.       else
  47.         prog->xp_Speed = prog->xp_UCur / (secs + 1);
  48.  
  49.       prog->xp_Done = 100 * prog->xp_UCur/prog->xp_ULen;
  50.       prog->xp_CF = 100 - 100 * prog->xp_CCur / prog->xp_UCur;
  51.     }
  52.     if(prog->xp_CF < 0)
  53.       prog->xp_CF = 0;
  54.  
  55. #ifdef DEBUG
  56.     if((hk = (struct Hook *) MyCallHookPkt(hk, prog A4SUPP2)))
  57.     {
  58.       DebugError("callprogress: Chunk hook returned error %lx", hk);
  59.     /* } - to allow {} matching */
  60. #else
  61.     if(MyCallHookPkt(hk, prog A4SUPP2))
  62.     {
  63. #endif
  64.       xbuf->xb_Result = XPKERR_ABORTED;
  65.     }
  66.   }
  67.  
  68.   if(sem)
  69.     ReleaseSemaphore((struct SignalSemaphore *) sem);
  70.  
  71.   return xbuf->xb_Result;
  72. }
  73.  
  74. #endif /* XPKMASTER_PROGRESS_C */
  75.